<template>
  <div class="boxCard">
    <h3 style="color: #333; text-align: center; margin-bottom: 10px">
      添加疑问
    </h3>

    <div
      style="width: 100%; height: 80vh; overflow-y: auto; overflow-x: hidden"
    >
      <el-row :gutter="12">
        <el-form :model="addForm" :rules="rules" ref="form">
          <el-col :span="24">
            <el-form-item label="问题描述" prop="issue">
              <el-input
                placeholder="请输入问题描述"
                v-model="addForm.issue"
                type="textarea"
                :rows="15"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>

      <div style="text-align: center">
        <el-button type="primary" style="width: 100%" @click="confirmResult"
          >提交疑问</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { addIssue } from "@/api/app";
export default {
  data() {
    return {
      addForm: {},

      rules: {
        issue: [{ required: true, message: "请输入问题描述", trigger: "blur" }],
      },
    };
  },

  methods: {
    // 提交问题
    async confirmResult() {
      // 校验
      this.$refs.form.validate(async (flag) => {
        if (flag) {
          try {
            let result = await addIssue({
              ...this.addForm,
              isAnswer: "0", // 表示未解答
              answer: "---",
            });
            if (result.code == 20000) {
              this.$message.success("问题保存成功");
              this.addForm = {};
            } else {
              this.$message.error(result.msg);
            }
          } catch (error) {
            this.$message.error(error);
          }
        }
      });
    },
  },
};
</script>

<style scoped></style>
